package com.tuweiya.study.springmvc001.observerPattern.subject.impl;

import com.tuweiya.study.springmvc001.observerPattern.observer.IObservers;
import com.tuweiya.study.springmvc001.observerPattern.subject.IPrettyGirl;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: Mr_tu
 * @Date: Create in 13:41 2018/6/7
 * @Description: 具体主题
 */
public class AngelbabySubject implements IPrettyGirl {
    /**
     * 观察者集合
     * 将有关状态存入具体的观察者对象
     */
    private List<IObservers> mList = new ArrayList<>();

    @Override
    public void addObservers(IObservers iObservers) {
        mList.add(iObservers);
    }

    @Override
    public void deleteObservers(IObservers iObservers) {
        mList.remove(iObservers);
    }

    @Override
    public void notifyAllObservers(String msg) {
        // 在具体主题发生改变时，给所有登记过的观察者发送通知
        mList.forEach(list -> list.updateMsg(msg));
    }
}
